package com.ternnetwork.oa.service.impl.dashboard;

import com.ternnetwork.commons.model.http.BaseResponse;
import com.ternnetwork.core.accesscontroll.entity.User;
import com.ternnetwork.core.accesscontroll.service.UserService;
import com.ternnetwork.oa.repository.note.NoteRepository;
import com.ternnetwork.oa.repository.work.EventUserRepository;
import com.ternnetwork.oa.service.dashboard.DashboardService;
import com.ternnetwork.oa.vo.dashboard.DashboardVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;


@Service
public class DashboardServiceImpl implements DashboardService {

    @Autowired
    private NoteRepository noteRepository;

    @Autowired
    private EventUserRepository eventUserRepository;

    @Autowired
    private UserService userService;


    public BaseResponse getData( String username) {

        BaseResponse baseResponse =new BaseResponse();

        DashboardVo dashboardVo=new DashboardVo();

        User loginUser=userService.findByName(username);

        Long noteCount=noteRepository.getCount(loginUser.getId());

        Long eventCount=eventUserRepository.getCount(loginUser.getId(), new Date());

        dashboardVo.setNoteCount(noteCount);

        dashboardVo.setEventCount(eventCount);

        baseResponse.setSccucess(dashboardVo);

        return baseResponse;

    }


}
